﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace agvcsimulator.GUI
{
    public delegate void deleLEDButton(object sender , int btnID , bool set);
    /// <summary>
    /// Interaction logic for UCLEDButton.xaml
    /// </summary>
    public partial class UCLEDButton : UserControl
    {
        public event deleLEDButton onLEDButtonChanged;

        [Category("LEDProperty")]
        public string ButtonName
        {
            get { return lbName.Content.ToString(); }
            set {lbName.Content = value;}
        }

        [Category("LEDProperty")]
        public int ButtonID
        {
            get;
            set;
        }

        [Category("LEDProperty")]
        public int NodeID
        {
            get;
            set;
        }

        public UCLEDButton()
        {
            InitializeComponent();

            InitUI();
        }

        void InitUI()
        {
            lbName.Content = string.IsNullOrEmpty(ButtonName)? "Name" : ButtonName;
        }

        private void Off_MouseUp(object sender, MouseButtonEventArgs e)
        {
            LEDOn();
        }

        private void On_MouseUp(object sender, MouseButtonEventArgs e)
        {
            LEDOff();
        }

        void LEDOn()
        {
            On.Visibility = Visibility.Visible;
            Off.Visibility = Visibility.Hidden;

            if (onLEDButtonChanged != null)
                onLEDButtonChanged(this, ButtonID, true);
        }

        void LEDOff()
        {
            On.Visibility = Visibility.Hidden;
            Off.Visibility = Visibility.Visible;

            if (onLEDButtonChanged != null)
                onLEDButtonChanged(this, ButtonID, false);
        }
    }
}
